
#include "../Math/Vector3.h"
#include "../Math/Matrix4.h"
#include "Camera.h"
#include "Utilities.h"


namespace
{
	starMatrix4 CreatePerspectiveProjectionMatrix(float fovy, float aspectRatio, float nearPlane, float farPlane)
	{
		float	yScale = Cotangent(DegreesToRadians(fovy / 2));
		float	xScale = yScale / aspectRatio;
		float	frustumLength = farPlane - nearPlane;

		return starMatrix4(	xScale	,0		,0												,0	,
							0		,yScale	,0												,0	,
							0		,0		,-((farPlane + nearPlane) / frustumLength)		,-1	,
							0		,0		,-((2 * nearPlane * farPlane) / frustumLength)	,0	);
	}
}


Camera::Camera()
{
	Camera::Camera( 60, (float)4/3, 1.0f, 100.0f);
}

Camera::Camera( float fovy, float aspectRatio, float nearPlane, float farPlane)
{
	mFovy			= fabs(fovy); 
	mAspectRatio	= fabs(aspectRatio); 
	mNearPlane		= fabs(nearPlane); 
	if(farPlane <= mNearPlane ) {
		mFarPlane = mNearPlane +1.0f;
	} else {
		mFarPlane = farPlane;
	}

	mPos.Zero();
	mAngle.Zero();

	mMoveSpeed		= 1.0f;	
	mRotateSpeed	= 1.0f;

	mPerspectiveProjectMatrix = CreatePerspectiveProjectionMatrix(mFovy, mAspectRatio, mNearPlane, mFarPlane);
}


Camera::~Camera()
{
}

void Camera::SetMoveSpeed(float speed)
{
	mMoveSpeed = speed;
}

void Camera::SetRotateSpeed(float speed)
{
	mRotateSpeed = speed;
}

void Camera::Move(starVector3 direct)
{
	direct.Normalize();
	direct *= mMoveSpeed;

	mPos += direct;

	mViewMatrix = TranslateMatrix(matrix4_identity, mPos);
}


void Camera::Rotate(starVector3 angle)
{

}

